package com.interview.rpc.protocol;

import java.io.Serializable;
import java.util.Arrays;

/**
 * RPC请求对象
 * 
 * 这个类用于封装客户端发起的RPC调用请求，包含调用哪个类的哪个方法以及参数信息
 * 实现Serializable接口是为了能够通过网络传输该对象
 */
public class Request implements Serializable {
    private static final long serialVersionUID = 1L;
    
    // 请求的唯一标识，用于匹配请求和响应
    private String requestId;
    // 要调用的类名（接口名）
    private String className;
    // 要调用的方法名
    private String methodName;
    // 方法参数的类型列表，用于方法重载时区分具体方法
    private Class<?>[] parameterTypes;
    // 方法调用时传入的实际参数值
    private Object[] parameters;
    
    // Constructors
    public Request() {}
    
    public Request(String requestId, String className, String methodName, Class<?>[] parameterTypes, Object[] parameters) {
        this.requestId = requestId;
        this.className = className;
        this.methodName = methodName;
        this.parameterTypes = parameterTypes;
        this.parameters = parameters;
    }
    
    // Getters and Setters
    public String getRequestId() {
        return requestId;
    }
    
    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }
    
    public String getClassName() {
        return className;
    }
    
    public void setClassName(String className) {
        this.className = className;
    }
    
    public String getMethodName() {
        return methodName;
    }
    
    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }
    
    public Class<?>[] getParameterTypes() {
        return parameterTypes;
    }
    
    public void setParameterTypes(Class<?>[] parameterTypes) {
        this.parameterTypes = parameterTypes;
    }
    
    public Object[] getParameters() {
        return parameters;
    }
    
    public void setParameters(Object[] parameters) {
        this.parameters = parameters;
    }
    
    @Override
    public String toString() {
        return "Request{" +
                "requestId='" + requestId + '\'' +
                ", className='" + className + '\'' +
                ", methodName='" + methodName + '\'' +
                ", parameterTypes=" + Arrays.toString(parameterTypes) +
                ", parameters=" + Arrays.toString(parameters) +
                '}';
    }
}